import java.util.Stack;


//括号匹配
class Solution {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<Character>();
        for (int i = 0; i < s.length(); i++) {
            char key1 = s.charAt(i);

            if (key1 == '{' || key1 == '[' || key1 == '(') {
                stack.push(key1);
            } else {
                if (stack.empty()) {
                    return false;
                } else {
                    char key2 = stack.peek();
                    if (key2 == '(' && key1 == ')' || key2 == '[' && key1 == ']' || key2 == '{' && key1 == '}') {
                        stack.pop();
                    } else
                        return false;
                }
            }
        }
        if (!stack.empty())
            return false;
        return true;
    }

    public class Paren_Match {
        public static void main(String[] args) {
            String s = "{[]}";   //"()[]{}"
            Solution solution = new Solution();
            System.out.println(solution.isValid(s));
        }
    }
}